package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ初始化信息（队列、交换机、绑定关系）的配置类
 */
@Configuration
public class RabbitConfig {
    /**
     * 简单工作模型-声明队列
     * @return
     */
    @Bean
    public Queue simpleQueue(){
        return new Queue("simple.queue");
    }
    /**
     * 工作队列模型-声明队列
     * @return
     */
    @Bean
    public Queue workQueue(){
        return new Queue("work.queue");
    }

    /**
     * 广播模型-声明交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout.exchange");
    }

    /**
     * 广播模型-声明队列1
     * @return
     */
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }

    /**
     * 广播模型-声明队列2
     * @return
     */
    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }

    /**
     * 广播模型-创建绑定关系-绑定交换机和队列1
     * @return
     */
    @Bean
    public Binding bindFanoutQueue1(FanoutExchange fanoutExchange,Queue fanoutQueue1){
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }
    /**
     * 广播模型-创建绑定关系-绑定交换机和队列2
     * @return
     */
    @Bean
    public Binding bindFanoutQueue2(FanoutExchange fanoutExchange,Queue fanoutQueue2){
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }

    /**
     * 路由模型-声明交换机
     * @return
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct.exchange");
    }

    /**
     * 路由模型-声明队列3
     * @return
     */
    @Bean
    public Queue directQueue3(){
        return new Queue("direct.queue3");
    }

    /**
     * 路由模型-创建交换机和队列3的绑定关系
     * @param directExchange
     * @param directQueue3
     * @return
     */
    @Bean
    public Binding bindDirectQueue3(DirectExchange directExchange,Queue directQueue3){
        return BindingBuilder.bind(directQueue3).to(directExchange).with("pink");
    }

    /**
     * 声明队列
     * @return
     */
    @Bean
    public Queue objectQueue(){
        return new Queue("object.queue");
    }
}
